#include "stdafx.h"
#include <string>
#include <iostream>
#include "CPerson.h"
#include <sstream>


//CPerson::CPerson(string Fname, string Lname, string FaterN, int sx,int y, int m, int d)
CPerson::CPerson(string Fname, string Lname, string FaterN, int sx,string dateG)
   {
      FirstName=Fname;
      LastName=Lname;	
      FaterName=FaterN;
      sex=sx;
      //year= y;
      //mount = m;
      //date = d;
      //num=0;
	  date = dateG;
   }
CPerson::CPerson()
   {
      FirstName=" ";
      LastName=" ";	
      FaterName=" ";
      sex=0;
      //year= 0;
      //mount = 0;
      //date = 0;
      //num=0;
	  date = "0.0.0";
   }
      
string CPerson::getFName() const
   {  
      return FirstName;

   }
   
string CPerson::getLName() const
   {
      return LastName;
   }
int CPerson::getSex() const
   {
      return sex;
   }

string CPerson::getFatName() const
	{
		return FaterName;
	}
//int CPerson::getNum()
  // {
    //  return num;
  // }
   
//int CPerson::getYear()
 //  {
  //    return year;
  // }

//int CPerson::getMount()
 //  {
  //    return mount;
  // }

//int CPerson::getDate()
 //  {
   //   return date;
  // }

string CPerson::getDateG() const
	{
		//string str;
		
		//std::ostringstream s;
		//s << date << '.' << mount << '.' << year;
		//std::string straka=s.str();
		//str = s.str();
		
		//return str;
		return date;
	}
      
void CPerson::printPerson()
   {
      cout<<endl<<"Описание персоны: "<<FirstName<<"  "<<LastName;
   }

string CPerson::getAll()
	{
		std::string strperson;
		//ostringstream sa;
		//sa << date<< '.' << mount << '.' << year;;
		std::string stsex;
		if (sex == 1) stsex = "Sex: female";
		else stsex = "Sex: male";
		strperson = LastName + "  " + FirstName +  " " + FaterName  +" " + date + " " + stsex;
		return strperson;
		
	}
void CPerson:: setAll(string Fname, string Lname, string FaterN,string dateG)
 {
	 FirstName=Fname;
      LastName=Lname;	
      FaterName=FaterN;
      //sex=sx;
	  date = dateG;
 }

std::ostream& operator<<(std::ostream& str, const CPerson &pers)
{
	str << pers.getFName() << std::endl;
	str << pers.getFatName() << std::endl;
	str << pers.getLName() << std::endl;
	str << pers.getDateG() << std::endl;

	str << manip(sex_vid,pers.getSex()) << std::endl;
	
	return str;
}
	
std::istream& operator>>(std::istream& str,CPerson &pers)
{
	//std::getline(str,pers.FirstName);
	str >> pers.FirstName;
	str >> pers.FaterName;
	str >> pers.LastName;
	str >> pers.date;
	// считывание пола
	//str >> manip();
	std::string sex;
	str >> sex;
	//str >> pers.sex;
	if ((sex == "m") || (sex == "0"))
		pers.sex = 0;
	else if ((sex == "f") || (sex == "1"))
		pers.sex = 1;
	else pers.sex = 99;

	if (!((pers.sex == 0 ) || (pers.sex == 1)))
	{
		CTreeException noNode(5,"CPerson operator>>	",pers.sex,9);
		throw noNode;
	}
	return str;
}
bool operator==(const CPerson &pers1,const CPerson &pers2)
{
	bool b=true;
	if ((pers1.getDateG() == "00.00.00") || (pers1.getDateG() == ""))b = (b & true);
	else b =(b & (pers1.getDateG() == pers2.getDateG()));
		 
	if (pers1.getFatName() == "") b=(b & true);
	else b =(b & (pers1.getFatName() == pers2.getFatName()));

	if (pers1.getFName() == "") b=(b & true);
	else b =(b & (pers1.getFName() == pers2.getFName()));

	if (pers1.getLName() == "") b = (b & true);
	else b =(b & (pers1.getLName() == pers2.getLName()));
		
	if (pers1.getSex() == pers2.getSex()) b = (b & true);
	else b = false;
	
	return b;

}

bool operator!=(const CPerson &pers1,const CPerson &pers2)
{
if ((pers1.getDateG() != pers2.getDateG()) || (pers1.getFatName() != pers2.getFatName()) || (pers1.getFName() != pers2.getFName()) 
	|| (pers1.getLName() != pers2.getLName()) || (pers1.getSex() != pers2.getSex())) return true;
	else return false;
}

inline CManip manip(int t, int s)
{
	return CManip(t,s);
}

std::ostream& operator<<(std::ostream& str,CManip& m)
{
	if (m.m_type == 1)	str << m.m_sex;
	else
		if (m.m_type == 0)
		{
			switch (m.m_sex)
			{
			case 1:
				str << 'f';
				break;
			case 0:
				str << 'm';
				break;
			}

		}
	
	return str;		
}